//
//  GKZYUniversityQueryViewController.m
//  GKZYAid
//
//  Created by lanou3g on 16/2/27.
//  Copyright © 2016年 GKZYAid. All rights reserved.
//

#import "GKZYUniversityQueryViewController.h"
#import "MJRefresh.h"
#import "GKZYBatchQueryBarButtonItemView.h"
#import "MyDefine.h"
#import "GKZYSortLeftBarButtonItemView.h"
#import "GKZYUniversityMajorView.h"
#import "GKZYUniversityQueryModel.h"
#import "GKZYUniversityListCell.h"
#import "Urls.h"
#import <AFNetworking.h>
#import "GKZYUniversityDetailController.h"
#import "GKZYUserSortDataHandel.h"
#import "GKZYUserSortViewController.h"
#import "MBProgressHUD.h"

//Tag 值1001开始

@interface GKZYUniversityQueryViewController ()<UITableViewDataSource,UITableViewDelegate>{
    //HUD（Head-Up Display，意思是抬头显示的意思）
    MBProgressHUD *HUD;
}



#pragma mark +++++++++++++   筛选区  ++++++++++++++++++
//地区
@property(nonatomic,strong)GKZYBatchQueryBarButtonItemView *locationBBI;
//地区tableView
@property(nonatomic,strong)UITableView *locationTableView;
//是否下拉地区
@property(nonatomic,assign)BOOL dropDownLocation;
//地区数据源
@property(nonatomic,strong)NSArray *locationDataArray;

//专业
@property(nonatomic,strong)GKZYBatchQueryBarButtonItemView *majorBBI;
//专业tableview
@property(nonatomic,strong)GKZYUniversityMajorView *majorView;
//是否下拉专业
@property(nonatomic,assign)BOOL dropDownMajor;
//专业数据源
@property(nonatomic,strong)NSArray *majorArray;
@property(nonatomic,strong)NSDictionary *majorDictionary;
//专业tableview
@property(nonatomic,strong)UITableView *majorTableView;
//专业次分类tableview
@property(nonatomic,strong)UITableView *secondMajorTableView;
//专业大类
@property(nonatomic,strong)NSString *majorName;


//学校类别
@property(nonatomic,strong)GKZYBatchQueryBarButtonItemView *schoolTypeBBI;
//学校类别talbeview
@property(nonatomic,strong)UITableView *schoolTypeTableView;
//是否下拉类别
@property(nonatomic,assign)BOOL dropDownType;
//数据源
@property(nonatomic,strong)NSArray *schoolTypeArray;

//其他
@property(nonatomic,strong)GKZYBatchQueryBarButtonItemView *othersBBI;
//view
@property(nonatomic,strong)GKZYUniversityMajorView *otherTermsView;
//其他筛选条件tableview
@property(nonatomic,strong)UITableView *otherTableView;
//次分类tableview
@property(nonatomic,strong)UITableView *secondOtherTermsTableView;
//是否下拉其他
@property(nonatomic,assign)BOOL dropDownOther;
//专业数据源
@property(nonatomic,strong)NSArray *termsArray;
@property(nonatomic,strong)NSDictionary *termsDictionary;
@property(nonatomic,strong)NSArray *termsValueArray;
@property(nonatomic,strong)NSDictionary *termsValueDictionary;
@property(nonatomic,strong)NSString *termsKey;
@property(nonatomic,strong)NSString *termsValue;

//专业大类
@property(nonatomic,strong)NSString *termsName;

//背景view
@property(nonatomic,strong)UIView *backView;
//背景view是否展开
@property(nonatomic,assign)BOOL showBackView;

#pragma mark ++++++++++++   学校列表    ++++++++++++++
@property(nonatomic,strong)UITableView *universityListTableView;
@property(nonatomic,strong)NSMutableArray *universityDataArray;
//显示数据条数:
@property (nonatomic,assign)NSInteger dataCount;
//总数据量
@property(nonatomic,assign)NSInteger totalCount;


//修改按键
@property(nonatomic,strong)UILabel *modifyLab;

@end

@implementation GKZYUniversityQueryViewController

-(void)loadView{

    [super loadView];
    
    self.view.backgroundColor = [UIColor whiteColor];
    [self addLocationBBIWithString:@"地区"];
    [self addMajorBBIWithSring:@"开设专业"];
    [self addSchoolTypeBBIWithSring:@"学校类别"];
    [self addOthersBBIWithSring:@"按其他筛选"];
    self.navigationItem.title = @"学校查询";
    
    GKZYSortLeftBarButtonItemView *leftBar = [[GKZYSortLeftBarButtonItemView alloc]initWithFrame:CGRectMake(0, 0, 60, 30)];
    UITapGestureRecognizer *tap5 = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(back)];
    [leftBar addGestureRecognizer:tap5];
    UIBarButtonItem *leftBBI = [[UIBarButtonItem alloc]initWithCustomView:leftBar];
    self.navigationItem.leftBarButtonItem = leftBBI;
    self.tabBarController.tabBar.alpha = 0;
    self.universityListTableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 94, VCWIDTH, VCHEIGHT-99)];
    self.universityListTableView.dataSource = self;
    self.universityListTableView.delegate = self;
    self.universityListTableView.tag = 1007;
    self.universityListTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self.view addSubview:self.universityListTableView];
    
    [self addDropDownTableView];
    
    self.modifyLab = [[UILabel alloc]initWithFrame:CGRectMake(VCWIDTH -85, 33, 70, 20)];
    self.modifyLab.userInteractionEnabled = YES;
    self.modifyLab.textColor = [UIColor orangeColor];
    self.modifyLab.text = @"修改分数";
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(collectionAction)];
    [self.modifyLab addGestureRecognizer:tap];
    UIBarButtonItem *barBI = [[UIBarButtonItem alloc]initWithCustomView:self.modifyLab];
    self.navigationItem.rightBarButtonItem = barBI;
//初始为0；
    self.dataCount = 0;
}

-(NSMutableArray *)universityDataArray{

    if (_universityDataArray == nil) {
        _universityDataArray = [[NSMutableArray alloc]init];
    }
    return _universityDataArray;
}

#pragma mark +++++++++++    添加筛选button及tableview    ++++++++++++++++

-(void)addLocationBBIWithString:(NSString *)string{

    self.locationBBI = [[GKZYBatchQueryBarButtonItemView alloc]initWithFrame:CGRectMake(0, 64, KmainScreenBoundsWidth/4, 30)];
    [self.locationBBI setBlackDirectionWithTitleName:string];
    self.locationBBI.layer.borderColor = [[UIColor colorWithWhite:0.1 alpha:0.1]CGColor];
    self.locationBBI.layer.borderWidth = 0.5f;
    UITapGestureRecognizer *tap1 = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(showLocationTableView)];
    [self.locationBBI addGestureRecognizer:tap1];
    [self.view addSubview:self.locationBBI];

}

-(void)addMajorBBIWithSring:(NSString *)string{
    self.majorBBI = [[GKZYBatchQueryBarButtonItemView alloc]initWithFrame:CGRectMake(KmainScreenBoundsWidth/4, 64, KmainScreenBoundsWidth/4, 30)];
    [self.majorBBI setBlackDirectionWithTitleName:string];
    self.majorBBI.titleName.font = [UIFont systemFontOfSize:13];
    self.majorBBI.layer.borderColor = [[UIColor colorWithWhite:0.1 alpha:0.1]CGColor];
    self.majorBBI.layer.borderWidth = 0.5f;
    UITapGestureRecognizer *tap2 = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(showMajorTableView)];
    [self.majorBBI addGestureRecognizer:tap2];
    [self.view addSubview:self.majorBBI];
}

-(void)addSchoolTypeBBIWithSring:(NSString *)string{
    self.schoolTypeBBI = [[GKZYBatchQueryBarButtonItemView alloc]initWithFrame:CGRectMake(KmainScreenBoundsWidth/2, 64, KmainScreenBoundsWidth/4, 30)];
    [self.schoolTypeBBI setBlackDirectionWithTitleName:string];
    self.schoolTypeBBI.titleName.font = [UIFont systemFontOfSize:13];
    self.schoolTypeBBI.layer.borderColor = [[UIColor colorWithWhite:0.1 alpha:0.1]CGColor];
    self.schoolTypeBBI.layer.borderWidth = 0.5f;
    UITapGestureRecognizer *tap3 = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(showSchoolTypeTableView)];
    [self.schoolTypeBBI addGestureRecognizer:tap3];
    [self.view addSubview:self.schoolTypeBBI];
}

-(void)addOthersBBIWithSring:(NSString *)string{
    self.othersBBI = [[GKZYBatchQueryBarButtonItemView alloc]initWithFrame:CGRectMake(KmainScreenBoundsWidth*3/4, 64, KmainScreenBoundsWidth/4, 30)];
    [self.othersBBI setBlackDirectionWithTitleName:string];
    self.othersBBI.titleName.font = [UIFont systemFontOfSize:13];
    self.othersBBI.layer.borderColor = [[UIColor colorWithWhite:0.1 alpha:0.1]CGColor];
    self.othersBBI.layer.borderWidth = 0.5f;
    UITapGestureRecognizer *tap4 = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(showOtherMoreTableView)];
    [self.othersBBI addGestureRecognizer:tap4];
    [self.view addSubview:self.othersBBI];

}

-(void)addDropDownTableView{

    self.backView = [[UIView alloc]initWithFrame:CGRectMake(0, 94, VCWIDTH, 0)];
    self.backView.backgroundColor = [UIColor colorWithWhite:0.1 alpha:0.5];
    [self.view addSubview:self.backView];
    
    self.locationTableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 94, VCWIDTH, 0)style:(UITableViewStylePlain)];
    self.locationTableView.dataSource = self;
    self.locationTableView.delegate = self;
    self.locationTableView.tag = 1001;
    self.locationTableView.showsVerticalScrollIndicator = NO;
    [self.view addSubview:self.locationTableView];
    self.locationDataArray = @[@"不限",@"北京",@"天津",@"上海",@"重庆",@"河北",@"河南",@"云南",@"辽宁",@"黑龙江",@"湖南",@"安徽",@"山东",@"新疆",@"江苏",@"浙江",@"江西",@"湖北",@"广西",@"甘肃",@"山西",@"内蒙古",@"陕西",@"吉林",@"福建",@"贵州",@"广东",@"青海",@"西藏",@"四川",@"宁夏",@"海南"];
    
    self.majorView = [[GKZYUniversityMajorView alloc]initWithFrame:CGRectMake(0, 94, VCWIDTH, 0)];
    self.majorTableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, VCWIDTH*0.4, 0)];
    self.majorTableView.dataSource = self;
    self.majorTableView.delegate = self;
    self.majorTableView.tag = 1002;
    [self.majorView addSubview:self.majorTableView];
    self.majorView.layer.borderWidth = 0.5f;
    self.majorTableView.separatorStyle =  UITableViewCellSeparatorStyleNone;
    self.majorView.layer.borderColor = [[UIColor colorWithWhite:0.1 alpha:0.1]CGColor];
    self.majorTableView.showsVerticalScrollIndicator = NO;
    [self.view addSubview:self.majorView];
    self.majorArray = @[@"不限",@"哲学",@"经济学",@"法学",@"教育学",@"文学",@"历史学",@"理学",@"工学",@"农学",@"医学",@"管理学",@"艺术学"];
    self.majorDictionary = @{@"不限":@[@""],@"哲学":@[@"哲学类"],@"经济学":@[@"财政学类",@"经济与贸易类",@"金融学类",@"经济学类"],@"法学":@[@"政治学类",@"社会学类",@"公安学类",@"民族学类",@"法学类",@"马克思主义理论类"],@"教育学":@[@"教育学类",@"体育学类"],@"文学":@[@"中国语言文学类",@"外国语言文学类",@"新闻传播学类"],@"历史学":@[@"历史学类"],@"理学":@[@"地理科学类",@"地球物理学类",@"统计学类",@"天文学类",@"化学类",@"数学类",@"大气科学类",@"物理学类",@"海洋科学类",@"心理学类",@"地质学类",@"生物科学类"],@"工学":@[@"矿业类",@"仪器类",@"测绘类",@"土木类",@"机械类",@"纺织类",@"电气类",@"电子信息类",@"兵器类",@"公安技术类",@"计算机类",@"环境科学与工程类",@"能源动力类",@"地质类",@"化工与制药类",@"生物医学工程类",@"生物工程类",@"自动化类",@"航空航天类",@"轻工类",@"食品科学与工程类",@"林业工程类",@"建筑类",@"力学类",@"农业工程类",@"材料类",@"交通运输类",@"核工程类",@"水利类",@"安全科学与工程类",@"海洋工程类"],@"农学":@[@"动物生产类",@"自然保护与环境生态类",@"水产类",@"植物生产类",@"动物医学类",@"草学类",@"林学类"],@"医学":@[@"中医学类",@"口腔医学类",@"公共卫生与预防医学类",@"基础医学类",@"护理学类",@"法医学类",@"药学类",@"临床医学类",@"中药学类",@"医学技术类",@"中西医结合类"],@"管理学":@[@"工商管理类",@"旅游管理类",@"农业经济管理类",@"图书情报与档案管理类",@"电子商务类",@"工业工程类",@"公共管理类",@"物流管理与工程类",@"管理科学与工程类"],@"艺术学":@[@"音乐与舞蹈学类",@"设计学类",@"戏剧与影视学类",@"美术学类",@"艺术学理论类"]};
    
    self.schoolTypeTableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 94, VCWIDTH, 0)style:(UITableViewStylePlain)];
    self.schoolTypeTableView.dataSource = self;
    self.schoolTypeTableView.delegate = self;
    self.schoolTypeTableView.tag = 1004;
    self.schoolTypeTableView.showsVerticalScrollIndicator = NO;
    [self.view addSubview:self.schoolTypeTableView];
    self.schoolTypeArray = @[@"不限",@"工科",@"语言",@"综合",@"医药",@"体育",@"财经",@"艺术",@"民族",@"师范",@"林业",@"农业",@"政法",@"军事",@"党政"];
    
    self.otherTermsView = [[GKZYUniversityMajorView alloc]initWithFrame:CGRectMake(0, 94, VCWIDTH, 0)];
    self.otherTableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, VCWIDTH*0.3, 0)];
    self.otherTableView.dataSource = self;
    self.otherTableView.delegate = self;
    self.otherTableView.tag = 1005;
    [self.otherTermsView addSubview:self.otherTableView];
    self.otherTableView.separatorStyle =  UITableViewCellSeparatorStyleNone;
    self.majorView.layer.borderColor = [[UIColor colorWithWhite:0.1 alpha:0.1]CGColor];
    [self.view addSubview:self.otherTermsView];
    self.termsArray = @[@"录取概率",@"批次",@"学校级别",@"男女比例",@"读研比例",@"出国比例"];
    self.termsValueArray = @[@"touch_level",@"batch",@"sch_level",@"gender_level",@"master_level",@"abroad_level",@""];
    self.termsDictionary = @{@"录取概率":@[@"不限",@"可保底(录取概率98%以上)",@"较稳妥(录取概率%80-98%)",@"可冲击(录取概率50%--80%)",@"难录取(录取概率50%以下)"],@"批次":@[@"不限",@"本科一批",@"本科二批",@"本科三批",@"专科一批"],@"学校级别":@[@"不限",@"211",@"985",@"普通院校"],@"男女比例":@[@"不限",@"女生多",@"男生多",@"男女均衡"],@"读研比例":@[@"不限",@"小于20%",@"20%--30%",@"30%--40%",@"40%--50%",@"大于50%"],@"出国比例":@[@"不限",@"小于5%",@"5%--10%",@"10%--20%",@"大于20%"]};
    self.termsValueDictionary = @{@"touch_level":@[@"不限",@"bao",@"wen",@"chong",@"nan"],@"batch":@[@"不限",@"bk1",@"bk2",@"bk3",@"zk1"],@"sch_level":@[@"不限",@"211",@"985",@"normal"],@"gender_level":@[@"不限",@"female_gt",@"male_gt",@"balanced"],@"master_level":@[@"不限",@"lt20",@"in20-30",@"in30-40",@"in40-50",@"gt50"],@"abroad_level":@[@"不限",@"lt5",@"gt5",@"gt10",@"gt20"]};
    
    
}


-(void)collectionAction{
    
    GKZYUserSortViewController *userVC = [[GKZYUserSortViewController alloc]init];
    self.navigationController.navigationBar.alpha = 1;
    [self.navigationController pushViewController:userVC animated:YES];
    
}


-(void)addSecondTableView{

    NSArray *array = [self.majorDictionary objectForKey:self.majorName];
    if ([self.majorName isEqualToString:@"不限"]) {
        
    }else{
    if (array.count*40<VCHEIGHT/2) {
        self.secondMajorTableView = [[UITableView alloc]initWithFrame:CGRectMake(VCWIDTH*0.3, 0, VCWIDTH*0.7, array.count*40)];
        
    }else{
    
        self.secondMajorTableView = [[UITableView alloc]initWithFrame:CGRectMake(VCWIDTH*0.3, 0, VCWIDTH*0.7, VCHEIGHT/2)];
    }
    self.secondMajorTableView.tag = 1003;
    self.secondMajorTableView.dataSource = self;
    self.secondMajorTableView.delegate = self;
    self.secondMajorTableView.layer.borderColor = [[UIColor colorWithWhite:0.1 alpha:0.1]CGColor];
    self.secondMajorTableView.layer.borderWidth = 0.5f;
    [self.majorView addSubview:self.secondMajorTableView];
    }
}

-(void)addOtherTermsSecondTableView{

    NSArray *array = [self.termsDictionary objectForKey:self.termsName];
        if (array.count*40<VCHEIGHT/2) {
            self.secondOtherTermsTableView = [[UITableView alloc]initWithFrame:CGRectMake(VCWIDTH*0.3, 0, VCWIDTH*0.7, array.count*40)];
            
        }else{
            
            self.secondOtherTermsTableView = [[UITableView alloc]initWithFrame:CGRectMake(VCWIDTH*0.3, 0, VCWIDTH*0.7, VCHEIGHT/2)];
        }
        self.secondOtherTermsTableView.tag = 1006;
        self.secondOtherTermsTableView.dataSource = self;
        self.secondOtherTermsTableView.delegate = self;
        self.secondOtherTermsTableView.layer.borderColor = [[UIColor colorWithWhite:0.1 alpha:0.1]CGColor];
        self.secondOtherTermsTableView.layer.borderWidth = 0.5f;
        [self.otherTermsView addSubview:self.secondOtherTermsTableView];
 
}


- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self makeData];
    
    [self refreshData];
}

-(void)viewWillAppear:(BOOL)animated{
    
    [super viewWillAppear:animated];
    
    if (self.showBackView) {
        self.backView.frame = CGRectMake(0, 94, VCWIDTH, VCHEIGHT-94);
    }else{
        
        self.backView.frame = CGRectMake(0, 94, VCWIDTH, 0);
    }
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDelegate:self];
    [UIView setAnimationDuration:0.3];
    if (self.dropDownLocation) {
        self.locationTableView.frame = CGRectMake(0, 94, VCWIDTH, VCHEIGHT/2);
        self.locationBBI.direction.transform = CGAffineTransformMakeRotation(M_PI*1);
    }else{
        self.locationTableView.frame = CGRectMake(0, 94, VCWIDTH, 0);
        self.locationBBI.direction.transform = CGAffineTransformMakeRotation(0);
    }
    
    if (self.dropDownMajor) {
        self.majorView.frame = CGRectMake(0, 94, VCWIDTH, VCHEIGHT/2);
        self.majorTableView.frame = CGRectMake(0, 0, VCWIDTH*0.3, VCHEIGHT/2);
        self.majorBBI.direction.transform = CGAffineTransformMakeRotation(M_PI*1);
        
    }else{
        self.majorView.frame = CGRectMake(0, 94, VCWIDTH, 0);
        self.majorTableView.frame = CGRectMake(0, 0, VCWIDTH*0.3, 0);
        self.secondMajorTableView.frame = CGRectMake(VCWIDTH *0.3, 0, VCWIDTH*0.7, 0);
        self.majorBBI.direction.transform = CGAffineTransformMakeRotation(0);
        
    }
    
    if (self.dropDownType) {
        self.schoolTypeTableView.frame = CGRectMake(0, 94, VCWIDTH, VCHEIGHT/2);
        self.schoolTypeBBI.direction.transform = CGAffineTransformMakeRotation(M_PI*1);
    }else{
        self.schoolTypeTableView.frame = CGRectMake(0, 94, VCWIDTH, 0);
        self.schoolTypeBBI.direction.transform = CGAffineTransformMakeRotation(0);
    }
    
    if (self.dropDownOther) {
        self.otherTermsView.frame = CGRectMake(0, 94, VCWIDTH, VCHEIGHT/2);
        self.otherTableView.frame = CGRectMake(0, 0, VCWIDTH*0.3, VCHEIGHT/2);
        self.othersBBI.direction.transform = CGAffineTransformMakeRotation(M_PI*1);
        
    }else{
        self.otherTermsView.frame = CGRectMake(0, 94, VCWIDTH, 0);
        self.otherTableView.frame = CGRectMake(0, 0, VCWIDTH*0.3, 0);
        self.secondOtherTermsTableView.frame = CGRectMake(VCWIDTH *0.3, 0, VCWIDTH*0.7, 0);
        self.othersBBI.direction.transform = CGAffineTransformMakeRotation(0);
        
    }
    [UIView commitAnimations];
}

#pragma mark +++++++++++++       解析数据      ++++++++++++

-(void)makeData{

    //初始化进度框，置于当前的View当中
    HUD = [[MBProgressHUD alloc] initWithView:self.view];
    [self.view addSubview:HUD];
    
    //如果设置此属性则当前的view置于后台
    HUD.dimBackground = YES;
    
    //设置对话框文字
    HUD.labelText = @"请稍等";
    
    //显示对话框
    [HUD showAnimated:YES whileExecutingBlock:^{
        //对话框显示时需要执行的操作
        [self dataRequest];
    } completionBlock:^{
        //操作执行完后取消对话框
        [HUD removeFromSuperview];
        HUD = nil;
    }];
}


-(void)dataRequest{

    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"application/json", @"text/json", @"text/javascript",@"text/html", @"text/plain", nil];
    
    NSMutableDictionary *paraments = [[NSMutableDictionary alloc]init];
    [paraments setValue:SINGLETON.wl forKey:@"wl"];
    [paraments setValue:SINGLETON.loc_name forKey:@"loc_name"];
    [paraments setValue:SINGLETON.score forKey:@"score"];
    [paraments setValue:@"20" forKey:@"count"];
    [paraments setValue:[NSString stringWithFormat:@"%ld",(long)self.dataCount] forKey:@"start"];
    NSString *location = nil;
    if (![self.locationBBI.titleName.text isEqualToString:@"不限"] && ![self.locationBBI.titleName.text isEqualToString:@"地区"]) {
        location = self.locationBBI.titleName.text;
    }
    [paraments setValue: location forKey:@"region"];
    
    NSString *major = nil;
    if (![self.majorBBI.titleName.text isEqualToString:@"不限"] && ![self.majorBBI.titleName.text isEqualToString:@"开设专业"]) {
        major = self.majorBBI.titleName.text;
    }
    [paraments setValue:major forKey:@"major"];
    
    NSString *type = nil;
    if (![self.schoolTypeBBI.titleName.text isEqualToString:@"不限"] && ![self.schoolTypeBBI.titleName.text isEqualToString:@"学校类别"]) {
        type = self.schoolTypeBBI.titleName.text;
    }
    [paraments setValue:type forKey:@"sch_type" ];
    
    if (self.termsKey != nil && ![self.termsValue isEqualToString:@"不限"]) {
        [paraments setValue:self.termsValue forKey:self.termsKey];
    }
    
    NSLog(@"+++++++%@",paraments);
    [manager POST:KschoolListURL parameters:paraments success:^(NSURLSessionDataTask * _Nonnull task, id  _Nonnull responseObject) {
        
        NSDictionary *dict = responseObject[@"data"];
        self.totalCount = [dict[@"total"]integerValue];
        NSArray *array = dict[@"sch_list"];
        //        self.universityDataArray = [[NSMutableArray alloc]init];
        for (NSDictionary *dict in array) {
            GKZYUniversityQueryModel *model = [[GKZYUniversityQueryModel alloc]init];
            [model setValuesForKeysWithDictionary:dict];
            [self.universityDataArray addObject:model];
        }
        dispatch_async(dispatch_get_main_queue(), ^{
            [self.universityListTableView reloadData];
        });
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        NSLog(@"网络请求失败，错误代码%@",error);
    }];

}


-(void)refreshData{
   
        [self.universityListTableView addHeaderWithTarget:self action:@selector(headerRereshing)];
        [self.universityListTableView addFooterWithTarget:self action:@selector(footerRereshing)];
}

//下拉刷新:
- (void)headerRereshing{
    
    if (self.dataCount > 0) {
        self.dataCount -= 20;
        [self makeData];
        [self.universityListTableView headerEndRefreshing];
    }else{
        self.universityListTableView.headerRefreshingText = @"刷新数据";
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            
            [self.universityListTableView headerEndRefreshing];
        });
    }
}


//上拉加载:
- (void)footerRereshing{

    if (self.dataCount < self.totalCount) {
        self.dataCount += 20;
        [self makeData];
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            [self.universityListTableView footerEndRefreshing];
        });
    }else{
        self.universityListTableView.footerRefreshingText = @"没有更多数据";
        [self.universityListTableView footerEndRefreshing];
    }
}

-(void)back{
    self.tabBarController.tabBar.alpha = 1;
    [self.navigationController popViewControllerAnimated:YES];
}


#pragma mark ++++++++++++++    筛选区   +++++++++++++++

-(void)showLocationTableView{

    self.locationBBI.direction.image = [UIImage imageNamed:@"down"];
    self.locationBBI.titleName.textColor = [UIColor orangeColor];
    self.dropDownLocation = !self.dropDownLocation;
    self.showBackView = self.dropDownLocation;
    self.dropDownMajor = NO;
    self.majorBBI.direction.image = [UIImage imageNamed:@"blackdown"];
    self.majorBBI.titleName.textColor =  [UIColor colorWithRed:178/256.0 green:178/256.0 blue:178/256.0 alpha:1];
    self.dropDownOther = NO;
    self.schoolTypeBBI.direction.image = [UIImage imageNamed:@"blackdown"];
    self.schoolTypeBBI.titleName.textColor =  [UIColor colorWithRed:178/256.0 green:178/256.0 blue:178/256.0 alpha:1];
    self.dropDownType = NO;
    self.othersBBI.direction.image = [UIImage imageNamed:@"blackdown"];
    self.othersBBI.titleName.textColor =  [UIColor colorWithRed:178/256.0 green:178/256.0 blue:178/256.0 alpha:1];

    [self viewWillAppear:YES];
    
}

-(void)showMajorTableView{
    
    self.majorBBI.direction.image = [UIImage imageNamed:@"down"];
    self.majorBBI.titleName.textColor = [UIColor orangeColor];
    self.dropDownMajor = !self.dropDownMajor;
    self.showBackView = self.dropDownMajor;
    self.locationBBI.direction.image = [UIImage imageNamed:@"blackdown"];
    self.locationBBI.titleName.textColor =  [UIColor colorWithRed:178/256.0 green:178/256.0 blue:178/256.0 alpha:1];
    self.dropDownLocation = NO;
    self.schoolTypeBBI.direction.image = [UIImage imageNamed:@"blackdown"];
    self.schoolTypeBBI.titleName.textColor =  [UIColor colorWithRed:178/256.0 green:178/256.0 blue:178/256.0 alpha:1];
    self.dropDownType = NO;
    self.othersBBI.direction.image = [UIImage imageNamed:@"blackdown"];
    self.othersBBI.titleName.textColor =  [UIColor colorWithRed:178/256.0 green:178/256.0 blue:178/256.0 alpha:1];
    self.dropDownOther = NO;
    [self.secondMajorTableView removeFromSuperview];
    [self viewWillAppear:YES];
    
}


-(void)showSchoolTypeTableView{
    
    self.schoolTypeBBI.direction.image = [UIImage imageNamed:@"down"];
    self.schoolTypeBBI.titleName.textColor = [UIColor orangeColor];
    self.dropDownType = !self.dropDownType;
    self.showBackView = self.dropDownType;
    self.dropDownMajor = NO;
    self.majorBBI.direction.image = [UIImage imageNamed:@"blackdown"];
    self.majorBBI.titleName.textColor =  [UIColor colorWithRed:178/256.0 green:178/256.0 blue:178/256.0 alpha:1];
    self.dropDownOther = NO;
    self.othersBBI.direction.image = [UIImage imageNamed:@"blackdown"];
    self.othersBBI.titleName.textColor =  [UIColor colorWithRed:178/256.0 green:178/256.0 blue:178/256.0 alpha:1];
    self.dropDownLocation = NO;
    self.locationBBI.direction.image = [UIImage imageNamed:@"blackdown"];
    self.locationBBI.titleName.textColor =  [UIColor colorWithRed:178/256.0 green:178/256.0 blue:178/256.0 alpha:1];
    
    [self viewWillAppear:YES];

}


-(void)showOtherMoreTableView{
    
    self.othersBBI.direction.image = [UIImage imageNamed:@"down"];
    self.othersBBI.titleName.textColor = [UIColor orangeColor];
    self.dropDownOther = !self.dropDownOther;
    self.showBackView = self.dropDownOther;
    self.locationBBI.direction.image = [UIImage imageNamed:@"blackdown"];
    self.locationBBI.titleName.textColor =  [UIColor colorWithRed:178/256.0 green:178/256.0 blue:178/256.0 alpha:1];
    self.dropDownLocation = NO;
    self.schoolTypeBBI.direction.image = [UIImage imageNamed:@"blackdown"];
    self.schoolTypeBBI.titleName.textColor =  [UIColor colorWithRed:178/256.0 green:178/256.0 blue:178/256.0 alpha:1];
    self.dropDownType = NO;
    self.majorBBI.direction.image = [UIImage imageNamed:@"blackdown"];
    self.majorBBI.titleName.textColor =  [UIColor colorWithRed:178/256.0 green:178/256.0 blue:178/256.0 alpha:1];
    self.dropDownMajor = NO;
    [self.secondOtherTermsTableView removeFromSuperview];
    [self viewWillAppear:YES];

}


#pragma mark +++++++++++    tableview代理协议    ++++++++++++

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{

    switch (tableView.tag) {
        case 1001:{
            return self.locationDataArray.count;
        }
            break;
            
        case 1002:{
            return self.majorArray.count;
        }
            break;
            
        case 1003:{
            if ([self.majorName isEqualToString:@"不限"]) {
                  return 0;
            }
            return [self.majorDictionary[self.majorName] count];
        }
            break;
            
        case 1004:{
            return self.schoolTypeArray.count;
        }
            break;
            
        case 1005:{
            return self.termsArray.count;
        }
            break;
        case 1006:{
            return [self.termsDictionary[self.termsName]count];
        }
            break;
        default:{
            
            return self.universityDataArray.count;
        }
            break;
    }
}



- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

    
    switch (tableView.tag) {
        case 1001:{
            
            UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
            if (cell == nil) {
                cell =     [[UITableViewCell alloc]initWithStyle:(UITableViewCellStyleDefault) reuseIdentifier:@"cell"];
                
            }
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            cell.textLabel.text = self.locationDataArray[indexPath.row];
            cell.textLabel.font = [UIFont systemFontOfSize:14];
            return cell;
        }
            break;
            
        case 1002:{
            UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"majorCell"];
            if (cell == nil) {
                cell = [[UITableViewCell alloc]initWithStyle:(UITableViewCellStyleDefault) reuseIdentifier:@"majorCell"];
            }
            cell.textLabel.text = self.majorArray[indexPath.row];
            cell.textLabel.font = [UIFont systemFontOfSize:14];
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            cell.textLabel.highlightedTextColor = [UIColor orangeColor] ;
            return cell;
        }
            break;
            
        case 1003:{
        
            UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"secondCell"];
            if (cell == nil) {
                cell = [[UITableViewCell alloc]initWithStyle:(UITableViewCellStyleDefault) reuseIdentifier:@"secondCell"];
            }
            NSArray *dataArray = self.majorDictionary[self.majorName];
            cell.textLabel.text = dataArray[indexPath.row];
            cell.textLabel.font = [UIFont systemFontOfSize:14];
            UIView *view = [[UIView alloc]init];
            view.backgroundColor = [UIColor whiteColor];
            cell.selectedBackgroundView = view;
            return cell;
        }
            break;
            
        case 1004:{
        
            UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"typeCell"];
            if (cell == nil) {
                cell = [[UITableViewCell alloc]initWithStyle:(UITableViewCellStyleDefault) reuseIdentifier:@"typeCell"];
            }
            UIView *view = [[UIView alloc]init];
            view.backgroundColor = [UIColor whiteColor];
            cell.selectedBackgroundView = view;
            cell.textLabel.text = self.schoolTypeArray[indexPath.row];
            cell.textLabel.font = [UIFont systemFontOfSize:14];
            return cell;
        }
            break;
        case 1005:{
        
            UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"otherCell"];
            if (cell == nil) {
                cell = [[UITableViewCell alloc]initWithStyle:(UITableViewCellStyleDefault) reuseIdentifier:@"otherCell"];
            }
            cell.textLabel.text = self.termsArray[indexPath.row];
            cell.textLabel.font = [UIFont systemFontOfSize:14];
            UIView *view = [[UIView alloc]init];
            view.backgroundColor = [UIColor whiteColor];
            cell.textLabel.highlightedTextColor = [UIColor orangeColor];
            cell.selectedBackgroundView = view;
            return cell;
        }
            break;
        case 1006:{
            UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"otherSecondCell"];
            if (cell == nil) {
                cell = [[UITableViewCell alloc]initWithStyle:(UITableViewCellStyleDefault) reuseIdentifier:@"otherSecondCell"];
            }
            NSArray *array = [self.termsDictionary objectForKey:self.termsName];
            cell.textLabel.text = array[indexPath.row];
            cell.textLabel.font = [UIFont systemFontOfSize:14];
            UIView *view = [[UIView alloc]init];
            view.backgroundColor = [UIColor whiteColor];
            cell.selectedBackgroundView = view;
            return cell;
        }
            break;
        default:{
        
            GKZYUniversityListCell *cell = [tableView dequeueReusableCellWithIdentifier:@"listCell"];
            if (cell == nil) {
                cell = [[GKZYUniversityListCell alloc]initWithStyle:(UITableViewCellStyleDefault) reuseIdentifier:@"listCell"];
            }
            GKZYUniversityQueryModel *model = self.universityDataArray[indexPath.row];
            [cell configureTheCellWithModel:model];
            cell.backgroundColor =CustomGrayColor;
            cell.selectionStyle =  UITableViewCellSelectionStyleNone;
            return cell;
        }
            break;
    }
  
}


-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
  
    switch (tableView.tag) {
        case 1001:{
            [self.locationBBI removeFromSuperview];
            [self addLocationBBIWithString:self.locationDataArray[indexPath.row]];
            self.locationBBI.titleName.textColor = [UIColor orangeColor];
            self.locationBBI.direction.image = [UIImage imageNamed:@"down"];
            self.dropDownLocation = NO;
            self.showBackView = NO;
            [self.universityDataArray removeAllObjects];
            [self makeData];
            [self viewWillAppear:YES];
        }
            break;
            
        case 1002:{
            [self.majorBBI removeFromSuperview];
            [self addMajorBBIWithSring:self.majorArray[indexPath.row]];
            self.majorBBI.titleName.textColor = [UIColor orangeColor];
            self.majorBBI.direction.image = [UIImage imageNamed:@"down"];
            self.majorName = self.majorArray[indexPath.row];
            if ([self.majorName isEqualToString:@"不限"]) {
                self.dropDownMajor = NO;
                self.showBackView = NO;
            }else{
            [self.secondMajorTableView removeFromSuperview];
            [self addSecondTableView];
            }
            
            self.dropDownType = NO;
            [self.universityDataArray removeAllObjects];
            [self makeData];
            [self viewWillAppear:YES];
        }
            break;
            
        case 1003:{
            
            [self.majorBBI removeFromSuperview];
            NSArray *array = [self.majorDictionary objectForKey:self.majorName];
            [self addMajorBBIWithSring:array[indexPath.row]];
            self.majorBBI.titleName.textColor = [UIColor orangeColor];
            self.majorBBI.direction.image = [UIImage imageNamed:@"down"];
            self.dropDownMajor = NO;
            self.showBackView = NO;
            [self.secondMajorTableView removeFromSuperview];
            [self.universityDataArray removeAllObjects];
            [self makeData];
            [self viewWillAppear:YES];

        }
            break;
        case 1004:{
        
            [self.schoolTypeBBI removeFromSuperview];
            [self addSchoolTypeBBIWithSring:self.schoolTypeArray[indexPath.row]];
            self.schoolTypeBBI.titleName.textColor = [UIColor orangeColor];
            self.schoolTypeBBI.direction.image = [UIImage imageNamed:@"down"];
            self.dropDownType = NO;
            self.showBackView = NO;
            [self.universityDataArray removeAllObjects];
            [self makeData];
            [self viewWillAppear:YES];
        }
            break;
        case 1005:{
        
            [self.othersBBI removeFromSuperview];
            [self addOthersBBIWithSring:self.termsArray[indexPath.row]];
            self.othersBBI.titleName.textColor = [UIColor orangeColor];
            self.othersBBI.direction.image = [UIImage imageNamed:@"down"];
            self.termsName = self.termsArray[indexPath.row];
            self.termsKey = self.termsValueArray[indexPath.row];
            [self.secondOtherTermsTableView removeFromSuperview];
            [self addOtherTermsSecondTableView];
            [self viewWillAppear:YES];
            
        }
            break;
        case 1006:{
            
            [self.othersBBI removeFromSuperview];
            NSArray *array = [self.termsDictionary objectForKey:self.termsName];
            NSArray *valueArr = [self.termsValueDictionary objectForKey:self.termsKey];
            self.termsValue = valueArr[indexPath.row];
            [self addOthersBBIWithSring:array[indexPath.row]];
            self.othersBBI.titleName.textColor = [UIColor orangeColor];
            self.othersBBI.direction.image = [UIImage imageNamed:@"down"];
            self.dropDownOther= NO;
            self.showBackView = NO;
            [self.secondMajorTableView removeFromSuperview];
            [self.universityDataArray removeAllObjects];
            [self makeData];
            [self viewWillAppear:YES];
        }
            break;
        default:{
            GKZYUniversityDetailController *detailUniversity = [[GKZYUniversityDetailController alloc]init];
            GKZYUniversityQueryModel *model = self.universityDataArray[indexPath.row];
            detailUniversity.sch_id = model.sch_id;
            [self.navigationController pushViewController:detailUniversity animated:YES];
        }
            break;
    }

}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    if (tableView.tag == 1007) {
        return 120;
    }
    return 40;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
   
}


@end
